linear regression cost function derivation